#include "MathUtiles.h"
#include <cmath>

const sf::Vector2f& normalize(const sf::Vector2f& vec)
{
	if(vec.x == 0 && vec.y == 0)
		return vec;
	else
		return (1/sqrt(vec.x * vec.x + vec.y * vec.y))*vec;
}

float getNorme(const sf::Vector2f& vec)
{
	return sqrt(vec.x * vec.x + vec.y * vec.y);
}

const sf::Vector2f& getReflect(const sf::Vector2f& vec, const sf::Vector2f& normal)
{
	float dot = vec.x * normal.x + vec.y * normal.y;
	return normalize(vec - 2 * dot * normal);
}

int getIntRandom(int begin, int end)
{
	return std::rand()%(end-begin + 1) + begin;
}
float getFloatRandom(float begin, float end, int precision)
{
	float random = getIntRandom(begin * precision, end * precision);
	return random/precision;
}